home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- #include "shared.fx"
- #include "lighting.fx"
- #include "fog.fx"
-
- //------------------------------------------------------------------------------------------------------
- //- Static parameters
- //------------------------------------------------------------------------------------------------------
-
- texture DiffuseMap;
- texture LightMap;
-
- // I must lure them with a new shared ambient param that wont be smashed by the engine.
- shared float4 LightMapAmbient;
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- struct CVertexShaderInput
- {
- float4 Position : POSITION;
- float3 Normal : NORMAL;
- float2 DiffuseUv : TEXCOORD0;
- float2 LightmapUv: TEXCOORD1;
- };
-
- //------------------------------------------------------------------------------------------------------
-
- struct CVertexShaderOutput
- {
- float4 Position : POSITION;
- float2 DiffuseUv : TEXCOORD0;
- float2 LightmapUv : TEXCOORD1;
- FOG_OPTION_VERTEX_FIELD
- };
-
- //------------------------------------------------------------------------------------------------------
-
- struct CVertexShaderOutputLighting
- {
- float4 Position : POSITION;
- float2 DiffuseUv : TEXCOORD0;
- float3 LightVector : TEXCOORD1;
- float3 NormalVector : COLOR0;
- float3 DiffuseColor : COLOR1;
- // FOG_OPTION_VERTEX_FIELD
- FOG_OPTION_VERTEX_FIELD_HACK(TEXCOORD2)
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- CVertexShaderOutput OpaLightmapGeomTech1Pass1(const CVertexShaderInput input);
- CVertexShaderOutputLighting OpaLightmapGeomTech2Pass1(const CVertexShaderInput input);
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- CVertexShaderOutput OpaLightmapGeomTech1Pass1 (const CVertexShaderInput input)
- {
- CVertexShaderOutput output;
-
- // output position into world+view+projection space
- output.Position = mul (input.Position,WorldCameraProjection);
-
- // Diffuse Uv output
- output.DiffuseUv = input.DiffuseUv;
-
- // LightmapUv Uv output
- output.LightmapUv = input.LightmapUv;
-
- // fog computation
- FOG_OPTION_COMPUTE(output, output.Position);
-
- return output;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- CVertexShaderOutputLighting OpaLightmapGeomTech2Pass1 (const CVertexShaderInput input)
- {
- CVertexShaderOutputLighting output;
-
- // output position into world+view+projection space
- output.Position = mul (input.Position,WorldCameraProjection);
-
- // Diffuse Uv output
- output.DiffuseUv = input.DiffuseUv;
-
- // omnilight direction computation
- float4 omniDirection = ComputeVectorAndLength (ObjectLocalLightPosition[0],input.Position);
-
- // omnilight direction attenuation
- //omniDirection *= ComputeAttenuation (omniDirection.w,LightAttenuationFarStart[0],LightAttenuationFarEnd[0],LightAttenuationDelta[0]);
-
- output.DiffuseColor = DiffuseColor[0].xyz;
- output.DiffuseColor *= ComputeAttenuation (omniDirection.w,LightAttenuationFarStart[0],LightAttenuationFarEnd[0],LightAttenuationDelta[0]);
-
- // omnilight output to diffuse
- output.LightVector.xyz = omniDirection.xyz;
- output.NormalVector.xyz = input.Normal * 0.5f + 0.5f;
-
- // fog computation
- FOG_OPTION(float rFog = fog_linear(output.Position); output.Hack = float4(rFog, rFog, rFog, rFog));
-
- return output;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- sampler DiffuseSampler = sampler_state
- {
- Texture = <DiffuseMap>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = WRAP;
- AddressV = WRAP;
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- sampler LightTextureSampler = sampler_state
- {
- Texture = <LightTexture>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = CLAMP;
- AddressV = CLAMP;
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- sampler LightMapSampler = sampler_state
- {
- Texture = <LightMap>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = WRAP;
- AddressV = WRAP;
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- #define Pass1RenderStateBlock \
- CullMode = CW; \
- ZEnable = true; \
- ZFunc = LESSEQUAL; \
- ZWriteEnable = true; \
- AlphaBlendEnable = false; \
- AlphaTestEnable = true; \
- AlphaRef = 192; \
- AlphaFunc = GREATEREQUAL ; \
- FOG_OPTION_PARAMETERS
-
- //------------------------------------------------------------------------------------------------------
-
- #define LightingRenderStateBlock \
- CullMode = CW; \
- ZEnable = true; \
- ZFunc = LESSEQUAL; \
- ZWriteEnable = false; \
- AlphaBlendEnable = true; \
- SrcBlend = ONE; \
- DestBlend = ONE; \
- AlphaTestEnable = true; \
- AlphaRef = 192; \
- AlphaFunc = GREATEREQUAL ; \
- FogEnable = false
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique tech1
- <
- int Priority = 1;
- int TechniqueIndex = 0;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = ACCUMULATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- Sampler[0] = <DiffuseSampler>;
- Sampler[1] = <LightMapSampler>;
-
- Pass1RenderStateBlock;
-
- VertexShader = compile vs_1_1 OpaLightmapGeomTech1Pass1();
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- tex t1 // Light map
-
- mul r0.rgb,t1,t1.a + mov r0.a,t0.a
- mul_x4 r0.rgb,r0,t0
- };
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique tech2
- <
- int Priority = 1;
- int TechniqueIndex = 0;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = ACCUMULATED_LIGHTING;
- string RenderingType = "Lighting";
- >
- {
- pass pass1
- {
- Sampler[0] = <DiffuseSampler>;
- Sampler[1] = <LightTextureSampler>;
-
- LightingRenderStateBlock;
-
- VertexShader = compile vs_1_1 OpaLightmapGeomTech2Pass1();
-
- PixelShader =
- #ifdef FOG_OPTION_ENABLE
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- tex t1 // Renormalized light vector
- texcoord t2 // fog hack
-
- dp3_sat r0.rgb,t1_bx2,v0_bx2 + mov r0.a,t0.a
-
- mul r0.rgb,r0,v1
- mul_x2 r0.rgb,r0,t0
-
- // fog hack : colorFog = oldColor * (1.0f - FogDensity)
- // in fact i do oldColor * 1.0f
- mul_sat r0.rgb, r0, t2
- };
- #else
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- tex t1 // Renormalized light vector
-
- dp3_sat r0.rgb,t1_bx2,v0_bx2 + mov r0.a,t0.a
-
- mul r0.rgb,r0,v1
- mul_x2 r0.rgb,r0,t0
- };
- #endif
- }
- }
-
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique tech1Ambient
- <
- int Priority = 1;
- int TechniqueIndex = 1;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = ACCUMULATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- Sampler[0] = <DiffuseSampler>;
- Sampler[1] = <LightMapSampler>;
-
- Pass1RenderStateBlock;
-
- VertexShader = compile vs_1_1 OpaLightmapGeomTech1Pass1();
-
- PixelShaderConstant[0] = <LightMapAmbient>;
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- tex t1 // Light map
-
- mul r0.rgb,t1,t1.a + mov r0.a,t0.a
- mul_x4 r0.rgb,r0,t0
- mul r0.rgb,r0,c0
- };
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique tech2Ambient
- <
- int Priority = 1;
- int TechniqueIndex = 1;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = ACCUMULATED_LIGHTING;
- string RenderingType = "Lighting";
- >
- {
- pass pass1
- {
- Sampler[0] = <DiffuseSampler>;
- Sampler[1] = <LightTextureSampler>;
-
- LightingRenderStateBlock;
-
- VertexShader = compile vs_1_1 OpaLightmapGeomTech2Pass1();
-
- PixelShader =
- #ifdef FOG_OPTION_ENABLE
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- tex t1 // Renormalized light vector
- texcoord t2 // fog hack
-
- dp3_sat r0.rgb,t1_bx2,v0_bx2 + mov r0.a,t0.a
-
- mul r0.rgb,r0,v1
- mul_x2 r0.rgb,r0,t0
-
- // fog hack : colorFog = oldColor * (1.0f - FogDensity)
- // in fact i do oldColor * 1.0f
- mul_sat r0.rgb, r0, t2
- };
- #else
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- tex t1 // Renormalized light vector
-
- dp3_sat r0.rgb,t1_bx2,v0_bx2 + mov r0.a,t0.a
-
- mul r0.rgb,r0,v1
- mul_x2 r0.rgb,r0,t0
- };
- #endif
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique techTnL_0
- <
- int Priority = 1;
- int TechniqueIndex = 0;
- int DeviceType = TNL_ONLY;
- int LightingType = ACCUMULATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- WorldTransform[0] = <WorldCameraProjection>;
- IndexedVertexBlendEnable = false;
-
- Sampler[0] = <LightMapSampler>;
- Sampler[1] = <DiffuseSampler>;
-
- Pass1RenderStateBlock;
-
- TexCoordIndex[0] = 1;
- TexCoordIndex[1] = 0;
- TextureFactor = {0.0f,0.0f,0.0f,0.0f};
-
- ColorArg1[0] = TEXTURE;
- ColorArg2[0] = TFACTOR;
- ColorOp[0] = BLENDTEXTUREALPHA;
- AlphaArg1[0] = TEXTURE;
- AlphaOp[0] = SELECTARG1;
-
- ColorArg1[1] = TEXTURE;
- ColorArg2[1] = CURRENT;
- AlphaArg1[1] = TEXTURE;
- AlphaOp[1] = SELECTARG1;
- ColorOp[1] = MODULATE4X;
-
- ColorOp[2] = DISABLE;
- AlphaOp[2] = DISABLE;
-
- VertexShader = NULL;
- PixelShader = NULL;
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- #include "mesh_shadow.fx"
- #include "mesh_shadow_projector.fx"
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-